#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <ecgi.h>
#include <xmlsec/app.h>
#include <xmlsec/dl.h>

#include "prepaid.h"

int main(int argc, char **argv) {
  const char *value;
  xmlDocPtr doc;
  unsigned ret;
  
  assert(cgiInit() == ECGI_SUCCESS);
  xmlInitParser();
  assert(!xmlSecInit());
#ifndef XMLSEC_NO_CRYPTO_DYNAMIC_LOADING
  assert(!xmlSecCryptoDLLoadLibrary("openssl"));
#endif
  assert(!xmlSecCryptoAppInit(NULL));
  assert(!xmlSecCryptoInit());
  srand(getpid());
  cgiSetMaxSize(50000);
  value = cgiParam("key");
  assert(value);
  doc = validateXmlMem(URI_SCHEMA_CHARON, value, strlen(value));
  ret = pp_addkey(xmlDocGetRootElement(doc));
  printf("Content-type: text/plain\n\n");
  printf("%d", ret);
  return 0;
}
